<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateShopOrderAftersaleTable extends Migrator
{
    /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('shop_order_aftersale', ['comment' => '订单售后', 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci']);
        $table->addColumn('aftersale_sn', 'string', ['limit' =>  60, 'default' => '', 'comment' => '售后单号'])
            ->addColumn('user_id', 'integer', ['limit' =>  11, 'default' => 0, 'comment' => '用户'])
            ->addColumn('type', 'string', ['limit' => 60, 'null' => true, 'default' => null, 'comment' => '类型:refund=退款,return=退货,other=其他'])
            ->addColumn('mobile', 'string', ['limit' => 20, 'null' => true, 'default' => null, 'comment' => '联系方式'])
            ->addColumn('activity_id', 'integer', ['limit' =>  11, 'default' => 0, 'comment' => '活动'])
            ->addColumn('activity_type', 'string', ['limit' =>  255, 'null' => true, 'default' => null, 'comment' => '活动类型'])
            ->addColumn('order_id', 'integer', ['limit' =>  11, 'default' => 0, 'comment' => '订单'])
            ->addColumn('order_item_id', 'integer', ['limit' =>  11, 'default' => 0, 'comment' => '订单商品'])
            ->addColumn('goods_id', 'integer', ['limit' =>  11, 'default' => 0, 'comment' => '商品'])
            ->addColumn('goods_sku_price_id', 'integer', ['limit' => 11, 'default' => 0, 'comment' => '规格'])
            ->addColumn('goods_sku_text', 'string', ['limit' => 60, 'null' => true, 'default' => null, 'comment' => '规格名'])
            ->addColumn('goods_title', 'string', ['limit' => 255, 'default' => '', 'comment' => '商品名称'])
            ->addColumn('goods_image', 'string', ['limit' => 255, 'default' => '', 'comment' => '商品图片'])
            ->addColumn('goods_original_price', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, 'comment' => '商品原价'])
            ->addColumn('goods_price', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, 'comment' => '商品价格'])
            ->addColumn('discount_fee', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, 'comment' => '优惠费用'])
            ->addColumn('goods_num', 'integer', ['limit' => 10, 'default' => 0, 'comment' => '购买数量'])
            ->addColumn(Column::tinyInteger('dispatch_status')->setDefault(0)->setComment('发货状态:0=未发货,1=已发货,2=已收货'))
            ->addColumn('dispatch_fee', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, 'comment' => '发货费用'])
            ->addColumn(Column::tinyInteger('aftersale_status')->setDefault(0)->setComment('售后状态:-2=已取消,-1=拒绝,0=未处理,1=申请售后,2=售后完成'))
            ->addColumn(Column::tinyInteger('refund_status')->setDefault(0)->setComment('退款状态:0=未退款,1=已同意'))
            ->addColumn('refund_fee', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, 'comment' => '退款金额'])
            ->addColumn('reason', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '申请原因'])
            ->addColumn('content', 'string', ['limit' => 1024, 'null' => true, 'default' => null, 'comment' => '相关描述'])
            ->addColumn('create_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '创建时间'])
            ->addColumn('update_time', 'integer', ['limit'  => 10, 'null' => true, 'default' => null, 'comment' => '更新时间'])
            ->addColumn('delete_time', 'integer', ['limit'  => 10, 'null' => true, 'default' => null, 'comment' => '删除时间'])
            ->addIndex('aftersale_sn', ['unique'  =>  true])
            ->addIndex('user_id')
            ->addIndex('order_id')
            ->create();
    }

    /**
     * Migrate Down.
     */
    public function down()
    {
        $table = $this->table('shop_order_aftersale');
        $table->drop();
    }
}
